/**
 * 角色详情对话框（可用于添加和修改对话框）
 */
var CommunityUserInfo = {
	communityUserInfoData: {},
    ztreeInstance: null,
    validateFields: {}
};


/**
 * 清除数据
 */
CommunityUserInfo.clearData = function () {
    this.communityUserInfoData = {};
};

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
CommunityUserInfo.set = function (key, val) {
    this.communityUserInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
};


/**
 * 收集数据
 */
CommunityUserInfo.collectData = function () {
  
}
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
CommunityUserInfo.get = function (key) {
    return $("#" + key).val();
};

/**
 * 关闭此对话框
 */
CommunityUserInfo.close = function () {
    parent.layer.close(window.parent.CommunityUser.layerIndex);
};

CommunityUserInfo.getUploadCount = function () {
	mytime = setInterval(function () {
		//提交信息
		 var ajax = new $ax(Feng.ctxPath + "/communityUser/getUploadCount", function (data) {
			 if(data.data.count>=data.data.total_count)
			 {
				 clearInterval(mytime);
			 }
			 ;
			parent.$('#uploadText').html('正在执行第' + (data.data.count) + '/' + data.data.total_count + '条数据，请稍等');
			parent.$('#executeprogress').css("width",Math.round(data.data.count * 100 / data.data.total_count)+"%");
		 }, function (data) {
		     Feng.error("操作失败!" + data.responseJSON.message + "!");
		 });
		 ajax.setContentType("application/json");
		 ajax.start();
	
        },
        200);
	
}

/**
 * 上传excel 
 */
CommunityUserInfo.upload = function () {
	 var title=$("input[class='file-caption-name']").attr("title");
	 if(typeof(title)=="undefined"||title=="验证错误")
	 {
		 Feng.error("请选择上传的excel文件");
		 return;
	 }
	 var index= parent.layer.open({
		    type: 0,
		    title: false,
		    closeBtn: 0,
		    btn: false,
		    content: '<div id="uploadText">正在执行，请耐心等待... ...</div><div class="processcontainer" id="processcontainer"><div id="executeprogress" style="width:0%;background:#95CA0D;float:left;height:100%;text-align:center;line-height:150%"></div></div>'
		});
      parent.$('#processcontainer').css({"width":"450px","border":"1px solid #6C9C2C","height":"25px"});  
	  var formFile = new FormData();
	    var fileObj = document.getElementById("file").files[0];
	    formFile.append("upfile", fileObj);
	    var data = formFile;
	    $.ajax({
	        type: "POST",
	        url: "/communityUser/uploadReport",
	        data: data,
	        dataType: "json",
	        contentType: false, //必须
	        processData: false,//用于对data参数进行序列化处理 这里必须false
	        cache: false,//上传文件无需缓存
	        beforeSend:function()
	        {
	        	CommunityUserInfo.getUploadCount();
	        },
	        success: function (data) {
	            if(data.code == 200){
	                if(data.data.length==0){
	                Feng.success(data.message);
	        	    window.parent.CommunityUser.table.refresh();
	                CommunityUserInfo.close();
	            }else{
	            	var str="";
	            	for(var i=0;i<data.data.length;i++)
	            	{
	            		var t_data=data.data[i];
	            		str+="错误行数:第"+t_data.row+"行,"+"错误信息:"+t_data.error+"</br>";
	            	}
	           	    Feng.infoDetail("错误详情",str);
	           	    window.parent.CommunityUser.table.refresh();
	            }
	            }else
	            {
	            	Feng.error(data.message);
	            }
	         
	        },
	        complete:function()
	        {
	        	   parent.layer.close(index);
	        }
	    });
};
